/*
 * @lc app=leetcode.cn id=599 lang=typescript
 *
 * [599] 两个列表的最小索引总和
 */

// @lc code=start
function findRestaurant(list1: string[], list2: string[]): string[] {
    let cache = new Map<number, string[]>();

    let min = Infinity;
    list2.forEach((i, index2) => {
        const index1 = list1.indexOf(i);
        if (index1 === -1) return;
        const sum = index1 + index2;
        min = Math.min(sum, min);
        let old = cache.get(sum) || [];
        old.push(i);
        cache.set(sum, old);
    });
    return cache.get(min) || [];
}
// @lc code=end
